package com.company.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.base.common.persistence.Page;
import com.base.common.service.CrudService;
import com.base.common.utils.SQLUtil;
import com.company.dao.CompanyDeviceMapper;
import com.company.model.CompanyDevice;
import com.company.model.CompanyDevice;
import com.company.service.DeviceService;

@Service
public class DeviceServiceImpl extends
		CrudService<CompanyDeviceMapper, CompanyDevice> implements
		DeviceService {
	public List<CompanyDevice> findDeviceListByCompanyId(String companyId) {
		Map<String, String> params = new HashMap<String, String>();
		params.put("companyId", companyId);
		String sql = "SELECT t.id,t.device_no,t.device_name,t.depreciation_year,t.create_time,t.purpose,t.original_value,case t.depreciation_method  when  '1' then '直线折旧法' else '加速折旧法' end as depreciation_method,t.company_id from company_device t where t.company_Id = #{companyId} ";
		List<CompanyDevice> list = this.getList(sql, CompanyDevice.class, params);
		return list;
	}

	public boolean deleteDeviceByIds(String ids) throws Exception {
		String sql = "delete from company_device where id in ("
				+ SQLUtil.createInStr(ids) + ") ";
		int res = this.delete(sql);
		return true;
	}
	
	public CompanyDevice findDeviceById(String id) throws Exception {
		return this.get(id);
	}

	public boolean saveDevice(CompanyDevice companyDevice)
			throws Exception {
		int res = this.saveOrUpdate(companyDevice);
		return true;
	}
}
